package com.ma.controller.admin;

import com.ma.common.result.Result;
import com.ma.entity.Doctor;
import com.ma.service.IDoctorService;
import com.ma.service.impl.DoctorServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Value;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author ldc
 * @since 2023-08-28
 */
@CrossOrigin(origins = "*")//解决跨域问题
@RestController
@RequestMapping("admin/doctor")
@Slf4j
@Api(tags = "医生相关接口")
public class DoctorController {
    @Resource
    private DoctorServiceImpl doctorService;

    @GetMapping("/findAll")
    @ApiOperation(value = "查找所有医生")
    public Result findAllDoctor() {
        log.info("查找所有医生");
        List<Doctor> all = doctorService.findAll();
        return Result.success(all);
    }
    @GetMapping("/page")
    @ApiOperation(value = "分页查询")
    public Result page(int offset,int pageSize){
        List<Doctor> doctors = doctorService.selectDoctorByPage(offset, pageSize);
        return Result.success(doctors);
    }
    @DeleteMapping("/delDoctorById")
    @ApiOperation(value = "根据id删除医生")
    public Result delete(int id){
        int byId = doctorService.delDoctorById(id);
        if (byId!=0){
            return Result.success(1);
        }
        return Result.error("删除失败");
    }

    @PostMapping("/login")
    @ApiOperation(value = "医生登录")
    public Result login(String username, String password) {
        log.info("医生登录,username={},password={}", username, password);
        Doctor doctor = doctorService.login(username, password);
        return Result.success(doctor);
    }

}
